package com.yimi.appstore.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.yimi.appstore.R;
import com.yimi.appstore.api.ApiClient;
import com.yimi.appstore.util.SharedPrefsUtil;
import com.yimi.appstore.util.Util;

public class LoginActivity extends Activity {

	Context context;
	ProgressBar mPb;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		context = this;
		setContentView(R.layout.activity_login_layout);

	}
	
	@Override
	protected void onResume() {
		super.onResume();
		new LoginTask().execute();
	}

	class LoginTask extends AsyncTask<Void, Void, Boolean> {

		@Override
		protected Boolean doInBackground(Void... params) {
			if (!Util.isConnectNetOk(context)) {
				return null;
			}
			ApiClient api = new ApiClient();
//			boolean result = api.Login(context);
			api.getAppUpdateList(context);
			return null;
		}

		@Override
		protected void onPostExecute(Boolean result) {
			super.onPostExecute(result);
//			if (result == null) {
//				AlertDialog.Builder builder = new Builder(context);
//				builder.setTitle("提示");
//				builder.setMessage("网络不可用");
//				builder.setPositiveButton("退出", new OnClickListener() {
//					
//					@Override
//					public void onClick(DialogInterface dialog, int which) {
//						dialog.dismiss();
//						finish();
//					}
//				});
//				builder.setNegativeButton("设置网络", new OnClickListener() {
//					
//					@Override
//					public void onClick(DialogInterface dialog, int which) {
//						startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
//					}
//				});
//				builder.show();
//			} else {
//				if (result) {
					Toast.makeText(LoginActivity.this,
							"uid:" + SharedPrefsUtil.getValue(LoginActivity.this, SharedPrefsUtil.KEY_UID, 0),
							Toast.LENGTH_SHORT).show();
					Intent i = new Intent(context, MainActivity3.class);
					startActivity(i);
					finish();
//				} else {
//					finish();
//				}
//			}

		}

	}

}
